package com.wh.json;

import java.io.Serializable;

import net.sf.json.JSONObject;

public class JSONUtil {

	public static String toJson(Object o) {
		return JSONObject.fromObject(o).toString();
	}

	public static String toJsonMsg(boolean success, String msg) {
		Message m = new Message();
		m.setSuccess(success);
		m.setMsg(msg);
		return JSONObject.fromObject(m).toString();
	}

	public static String toJsonMsg(boolean success, String msg, Object o) {
		Message m = new Message();
		m.setSuccess(success);
		m.setMsg(msg);
		m.setValue(o);
		return JSONObject.fromObject(m).toString();
	}

	public static class Message implements Serializable {
		private static final long serialVersionUID = 1L;
		private boolean success;
		private String msg;
		private Object value;

		public boolean isSuccess() {
			return success;
		}

		public void setSuccess(boolean success) {
			this.success = success;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}

		public Object getValue() {
			return value;
		}

		public void setValue(Object value) {
			this.value = value;
		}
	}
}
